#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using System.Web;
using Agresso.Interface.Layer.Service;
using System.Collections;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class AlertDetailForm : Form
    {
        public AlertDetailForm(Alert alert)
        {
            InitializeComponent();
            textBoxAlertCreatedDate.Text = alert.alert_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxAlertID.Text = alert.alert_id.ToString();
            textBoxAlertStatus.Text = alert.alert_status.ToString();
            textBoxAlertType.Text = alert.alert_type.ToString();
            textBoxAlertUpdate.Text = alert.alert_modified_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxEntity.Text = alert.entity;
        }
        public AlertDetailForm(CommissionInvoice alert, string type)
        {
            InitializeComponent();
            textBoxAlertCreatedDate.Text = alert.pickup_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxAlertID.Text = alert.invoice_number;
            textBoxAlertStatus.Text = "PENDING";
            textBoxAlertType.Text = alert.company;
            textBoxAlertUpdate.Text = alert.pickup_update_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxEntity.Text = type;

            string[] details = alert.remarks.Split('-');
            listBoxDetails.Items.Clear();
            foreach (string detail in details)
            {
                if (detail.Trim() == "") continue;                
                listBoxDetails.Items.Add(detail.Trim());
            }
        }
        public AlertDetailForm(Statement alert, string type)
        {
            InitializeComponent();
            textBoxAlertCreatedDate.Text = alert.pickup_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxAlertID.Text = alert.statement_number;
            textBoxAlertStatus.Text = "PENDING";
            textBoxAlertType.Text = alert.company;
            textBoxAlertUpdate.Text = alert.pickup_update_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxEntity.Text = type;

            string[] details = alert.remarks.Split('-');
            listBoxDetails.Items.Clear();
            foreach (string detail in details)
            {
                if (detail.Trim() == "") continue;
                listBoxDetails.Items.Add(detail.Trim());
            }
        }

        public AlertDetailForm(BunkerPO alert, string type)
        {
            InitializeComponent();
            textBoxAlertCreatedDate.Text = alert.pickup_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxAlertID.Text = alert.enquiry_no;
            textBoxAlertStatus.Text = "PENDING";
            textBoxAlertType.Text = alert.supplier;
            textBoxAlertUpdate.Text = alert.pickup_update_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxEntity.Text = type;

            string[] details = alert.remarks.Split('-');
            listBoxDetails.Items.Clear();
            foreach (string detail in details)
            {
                if (detail.Trim() == "") continue;
                listBoxDetails.Items.Add(detail.Trim());
            }
        }
        public AlertDetailForm(VoyageMaster alert, string type)
        {
            InitializeComponent();
            textBoxAlertCreatedDate.Text = alert.pickup_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxAlertID.Text = alert.voyage_no.ToString();
            textBoxAlertStatus.Text = "PENDING";
            textBoxAlertType.Text = alert.vessel_name;
            textBoxAlertUpdate.Text = alert.pickup_update_date.ToString("dd-MMM-yyyy HH:mm");
            textBoxEntity.Text = type;

            string[] details = alert.remarks.Split('-');
            listBoxDetails.Items.Clear();
            foreach (string detail in details)
            {
                if (detail.Trim() == "") continue;
                listBoxDetails.Items.Add(detail.Trim());
            }
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if (listBoxDetails.SelectedItems.Count == 0) return;

            string p = listBoxDetails.SelectedItem.ToString();
            string error = getErrorCode(p);
            string code = getIDCode(p);

            SoftmarVesselMappingForm vesselform = null;
            SoftmarSupplierCustomerMappingForm supplierfrm = null;
            SoftmarProfitCentreMappingForm pcFrm = null;
            SoftmarGradeAccountMappingForm gaccFrm = null;
            SoftmarChargeTypeAccountMappingForm chrgFrm = null;
            SoftmarBunkerInventoryManagerMappingForm bimFrm = null;

            switch (error)
            {
                case "E001":
                    vesselform = new SoftmarVesselMappingForm(code);
                    vesselform.ShowDialog();
                    break;
                case "E002":
                    MessageBox.Show("Please contact Carina");
                    break;
                case "E003":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E004":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E005":
                    supplierfrm = new SoftmarSupplierCustomerMappingForm(code);
                    supplierfrm.ShowDialog();
                    break;
                case "E006":
                    supplierfrm = new SoftmarSupplierCustomerMappingForm(code);
                    supplierfrm.ShowDialog();
                    break;
                case "E007":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E008":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E009":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E010":
                    vesselform = new SoftmarVesselMappingForm(code);
                    vesselform.ShowDialog();
                    break;
                case "E011":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E012":
                    MessageBox.Show("Please update in Agresso, then execute");
                    break;
                case "E013":
                    MessageBox.Show("Please update in Agresso, then execute");
                    break;
                case "E014":
                    pcFrm = new SoftmarProfitCentreMappingForm(code);
                    pcFrm.ShowDialog();
                    break;
                case "E015":
                    MessageBox.Show("Please update Vessel '" + code + "' in Agresso, then execute");
                   // vesselform = new SoftmarVesselMappingForm(code);
                   // vesselform.ShowDialog();
                    break;
                case "E016":
                    MessageBox.Show("Please update the Voyage Master, then execute");
                    break;
                case "E017":
                    chrgFrm = new SoftmarChargeTypeAccountMappingForm(code);
                    chrgFrm.ShowDialog();
                    break;
                case "E018":
                    MessageBox.Show("Please update the Voyage Master, then execute");
                    break;
                case "E019":
                    gaccFrm = new SoftmarGradeAccountMappingForm(code);
                    gaccFrm.ShowDialog();
                    break;
                case "E020":
                    MessageBox.Show("Please check in Softmar, then execute");
                    break;
                case "E021":
                    supplierfrm = new SoftmarSupplierCustomerMappingForm(code);
                    supplierfrm.ShowDialog();
                    break;
                case "E022":
                    MessageBox.Show("Please update in Agresso, then execute");
                    break;
                case "E023":
                    MessageBox.Show("Please update in Softmar, then execute");
                    break;
                case "E024":
                    gaccFrm = new SoftmarGradeAccountMappingForm(code);
                    gaccFrm.ShowDialog();
                    break;
                case "E025":
                    vesselform = new SoftmarVesselMappingForm(code);
                    vesselform.ShowDialog();
                    break;
                case "E026":
                    MessageBox.Show("Please update in Softmar, then execute");
                    break;
                case "E027":
                    bimFrm = new SoftmarBunkerInventoryManagerMappingForm(code);
                    bimFrm.ShowDialog();
                    break;

            }
        }

        private string getErrorCode(string p)
        {
            StringBuilder sb = new StringBuilder();
            bool range= false;
            for (int x = 0; x < p.Length; x++)
            {
                
                if(p[x] == '[')
                    range = true;
                if (p[x] == ']')
                {
                    range = false;
                    break;
                }
                if (range)
                {
                    if (p[x] == '[' || p[x] == ']')
                        continue;
                    sb.Append(p[x]);
                }
            }
            return sb.ToString().Trim();
        }
        private string getIDCode(string p)
        {
            StringBuilder sb = new StringBuilder();
            bool range = false;
            for (int x = 0; x < p.Length; x++)
            {
                if (p[x] == '\'')
                {
                    if (!range)
                        range = true;
                    else
                    {
                        range = false;
                        break;
                    }
                }
                if (range)
                {
                    if (p[x] == '\'')
                        continue;
                    sb.Append(p[x]);
                }
            }
            return sb.ToString().Trim();
        }

    }
    public class ExecuteResolve
    {
        string alert = "";
        string alertType = "";
        string id = "";
        public ExecuteResolve(string alertX, string alerttypeX, string idX) 
        {
            alert = alertX;
            alertType = alerttypeX;
            id = idX;
        }
        public override string ToString()
        {
            return alert;
        }
    }
}